/**
* @ProjectName: ShopSytem
* @Title: UserDaoImpl.java 
* @Package com.element5th.shop.dao.user 
* @Description: 前台用户数据库相关操作
* @author 第五元素小组   
* @date 2012-10-26 15:51:48 
* @version V1.0   
*/ 
package com.element5th.shop.dao.user;


import com.element5th.shop.comm.BaseDao;
import com.element5th.shop.comm.SystemException;
import com.element5th.shop.comm.BaseDao;
import com.element5th.shop.dto.BaseDto;
import com.element5th.shop.entity.User;

/**
 * The Class UserDaoImpl.
 */
public class UserDaoImpl extends BaseDao implements IUserDao {

	/*  
	* Title: userLogin 
	* Description: 前台用户登录
	* @param dto 登录用户名及密码
	* @return 登录用户信息，登录失败则返回null
	* @see com.element5th.shop.dao.user.IUserDao#userLogin(com.element5th.shop.dto.BaseDto) 
	*/ 
	@Override
	public BaseDto userLogin(BaseDto dto) {
		return null;
	}

	/*  
	* Title: userRegister 
	* Description: 用户注册
	* @param dto 用户注册相关信息
	* @return 操作是否成功
	* @see com.element5th.shop.dao.user.IUserDao#userRegister(com.element5th.shop.dto.BaseDto) 
	*/ 
	@Override
	public boolean userRegister(BaseDto dto) throws SystemException{
		boolean flag;
		this.openConnection();
		flag=this.save(dto.getUser());	
		if(flag==false){
			this.rollback();
			throw new SystemException(2002, "用户注册插入数据库出错！");
		}
		this.commit();
		return true;
	}

	/*  
	* Title: updateBaseInfo 
	* Description: 更改用户信息
	* @param dto 用户信息及用户详细信息对象
	* @return 操作是否成功
	* @see com.element5th.shop.dao.user.IUserDao#updateBaseInfo(com.element5th.shop.dto.BaseDto) 
	*/ 
	@Override
	public boolean updateBaseInfo(BaseDto dto) {
		return false;
	}

	/*  
	* Title: viewUserInfo 
	* Description: 查看用户信息
	* @param dto 要查看的用户对象
	* @return 包含用户对象及用户信息对象
	* @see com.element5th.shop.dao.user.IUserDao#viewUserInfo(com.element5th.shop.dto.BaseDto) 
	*/ 
	@Override
	public BaseDto viewUserInfo(BaseDto dto) {
		User user = this.findByCol(User.class,"UserName",dto.getUser().getUserName());
		BaseDto bdto = new BaseDto();
		bdto.setUser(user);
		return bdto;
	}
	
	/*  
	* Title: userRegister 
	* Description: 用户注册
	* @param dto 用户注册基本信息
	* @return 操作是否成功
	* @see com.element5th.shop.dao.user.IUserDao#userRegister(com.element5th.shop.dto.BaseDto) 
	*/ 
	@Override
	public boolean userBaseRegister(BaseDto dto) throws SystemException{
		boolean flag;
		this.openConnection();
		flag=this.save(dto.getUserBase());	
		if(flag==false){
			this.rollback();
			throw new SystemException(2002, "用户注册基本信息插入数据库出错！");
		}
		this.commit();
		return true;
	}

}
